import {Controller, Render, Get, Param, Session} from "routing-controllers";
import { utils } from "../../utils/utils";
import { Service, Inject } from "typedi";
import { InfoServiceImpl } from "../../service/impl/InfoServiceImpl";

@Service()
@Controller()
export class InfoControllerHome {
	
	@Inject()
	private infoServiceImpl: InfoServiceImpl;
	
	@Get("/info/:type")
	@Render("home/page/info")
	public async Info(@Session() session, @Param("type") type: string): Promise<Object> {
		// 获取课程主体信息
		let courseList = await this.infoServiceImpl.getCourseByObjectId(type);
		// 获取课程下所属的视频章节
		let courseVideoList = await this.infoServiceImpl.getCourseVideoByObjectId(type);
		
		console.log("courseVideoList: ",courseVideoList)
		
		return {
			title: utils.titleName(`${courseList['courseTitle']} - 课程详情`),
			isShowAction: {
				header: true,
				footer: true
			},
			courseList: courseList,
			courseVideoList: courseVideoList,
			banner: {
				bannerTitle: courseList['courseTitle'],
				bannerUrl: courseList['courseImageUrl']
			},
			meta: {
				description: `${courseList['courseTitle']} ${courseList['courseDesc']}`
			},
			login: session.user ? session.user : false
		}
	}
	
}